<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* 车辆类型信息管理
*/
class Car_type extends MY_Controller {

	public function __construct()
	{
		parent::__construct();
		$this->load->model('Car_type_model');
	}
	//查询列表
	public function index()
	{
		$typename = $this->input->get_post('typename');
		$start =  intval($this->input->get_post('per_page'));

		$params = array(
			'typename' =>$typename 
			,'start' => $start
			,'length'=>$this->page_size);


		$result = $this->Car_type_model->select_page($params);
		
		$result['params'] = $params;

		//分页设置
		$base_url =  site_url("c=car_type&m=index&typename=$typename");
		$result['pagelink'] = $this->create_page_links($base_url,$result['count']);
		
		$this->show_view('carTypeList',$result);
		
	}

	//编辑
	public function edit()
	{

		$this->form_validation->set_rules('typename', '车辆类型', 'required');
		$typeid = $this->input->get_post('typeid');
		$typeeditsubmit = $this->input->post('typeeditsubmit');
		$resultinfo = $this->Car_type_model->select_by_id($typeid);
		$resultinfo['method'] ='edit';
		if($typeeditsubmit  && $this->form_validation->run())
		{
			 
			$typename = $this->input->get_post('typename');

			$result = $this->Car_type_model->update($typeid,array('typename'=>$typename));
			$this->show_message("编辑车辆类型信息成功",site_url("c=car_type&m=index"));
			
		}
		else
		{		
			
			$this->show_view('carTypeEdit',$resultinfo);
			
		}
	}
	//新增用户
	public function add()
	{
		$this->form_validation->set_rules('typename', '车辆类型', 'required');
		
		$typeeditsubmit = $this->input->post('typeeditsubmit');
		$resultinfo  =array('method'=>'add');
		if($typeeditsubmit  && $this->form_validation->run())
		{
			
			$typename = $this->input->get_post('typename');
 
			$result = $this->Car_type_model->insert(array('typename'=>$typename));

			$this->show_message("新增车辆类型信息成功",site_url("c=car_type&m=index"));
			
		}
		else
		{		
			
			$this->show_view('carTypeEdit',$resultinfo);
			
		}
	}
	//新增用户
	public function delete()
	{
		$typeid = $this->input->get_post('typeid');
		$result = $this->Car_type_model->delete($typeid);
		if($result['success'])
		{
			$this->show_message("删除车辆类型信息成功",site_url("c=car_type&m=index"));
		}
		else
		{
			$this->show_message($result['message'],site_url("c=car_type&m=index"));
		}
	}

 
}